import React, { Component,useEffect } from 'react';
import { Redirect } from 'react-router-dom';

export class AdminHome extends Component {
    constructor(props) {
        super(props)

       const token = sessionStorage.getItem("token") //get token from local storage 
        let loggedIn = true
        if (token == null) {
            loggedIn = false
        }
       
        this.state = {
            users: [],
            loggedIn
        }
        
       
    }

    componentDidMount() {
        var current_user = "";
        fetch(process.env.REACT_APP_API_LOGIN + 'Login' + '/GetUser', {
            // credentials: 'include',
            credentials: 'include',
            method: "GET",
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            }
        })
       
            .then((Response) => Response.json())
            .then((result) => {
                
                if (result > 0) {
                    current_user = result;
                    this.setState({ users: result });
                    alert(current_user);
                }
                else {
                    alert('Invelid user ');
                }
            },
                (error) => {
                    alert(error);
                })
    }


    render() {
        if (this.state.loggedIn == false)
        {
            return <Redirect to="/signin"/>
        }

        return (

            <div className="mt-5 d-flex justify-content-left">
                This is admin home 
            </div>
        )
    }

}